import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import ElementUI from 'element-ui';
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'home',
    component: ()=>import('@/views/home'),
    meta:{
      title:'首页',
      elIcon:'el-icon-s-home'
    },
    userType: ['01','00'],
    children:[
      {
        path: '/homeView',
        name: 'homeView',
        component: () => import('@/views/homeView/index'),
        meta:{
          title:'首页',
          elIcon:'el-icon-s-home'
        }
      },
    ]
  },
  {
    path: '/defaultSetting',
    name: 'defaultSetting',
    component: ()=>import('@/views/home'),
    meta:{
      title:'默认配置',
      elIcon:'el-icon-s-tools',
    },
    userType: ['00'],
    children:[
      {
        path: '/defaultSetting',
        name: 'defaultSetting',
        component: () => import('@/views/defaultSetting/defaultSetting'),
        meta:{
          title:'默认配置',
          elIcon:'el-icon-s-tools',
        }
      },
    ]
  },
  {
    path: '/tags',
    name: 'tags',
    component: ()=>import('@/views/home'),
    meta:{
      title:'标签管理',
      elIcon:'el-icon-s-finance',
    },
    userType: ['00'],
    children:[
      {
        path: '/tags',
        name: 'tagsIndex',
        component: () => import('@/views/tags/tags'),
        meta:{
          title:'标签管理',
          elIcon:'el-icon-s-finance',
        }
      },
    ]
  },

  {
    path: '/userList',
    name: 'userList',
    component: ()=>import('@/views/home'),
    meta:{
      title:'用户管理',
      elIcon:'el-icon-s-custom',
    },
    userType: ['00'],
    children:[
      {
        path: '/userList',
        name: 'apiConfig',
        component: () => import('@/views/users/index'),
        meta:{
          title:'用户管理',
          elIcon:'el-icon-s-custom',
        },
      },
    ]
  },
  {
    path: '/bot',
    name: 'bot',
    component: ()=>import('@/views/home'),
    meta:{
      title:'策略机器人',
      elIcon:'el-icon-s-help'
    },
    userType: ['01','00'],
    children:[
      {
        path: '/apiConfig',
        name: 'apiConfig',
        component: () => import('@/views/strategy/apiConfig'),
        meta:{
          title:'API配置',
          elIcon:'el-icon-s-tools'
        },
      },
      {
        path: '/myStrategy',
        name: 'myStrategy',
        component: () => import('@/views/strategy/myStrategy'),
        meta:{
          title:'我的策略',
          elIcon:'el-icon-s-order'
        },
      },
    ]
  },

  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login'),
    meta:{
      title:'登录页面',
      hidden:true,
    },
    userType: '01',
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/login/register'),
    meta:{
      title:'注册页面',
      hidden:true,
    },
    userType: '01',
  }
]
//解决重复点击报错的问题
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  if (to.meta.hidden==true&&to.meta.title!='登录页面'){
    ElementUI.Message({
      message: '您暂无权限访问该页面',
      type: 'error'
    });
    next({path: '/'})
  }else {
    next();
  }

});
export default router
